﻿#ifndef MSGSOCKET_H
#define MSGSOCKET_H

#include <QObject>
#include <QTcpSocket>
#include "globalvars.h"
#include "execsql.h"

class MsgSocket : public QObject
{
    Q_OBJECT
signals:
    void signalRegisterSocket(QString id, MsgSocket *socket);//建立连接时发送信号，保存到map中
    void signalLogoutSocket(QString id, MsgSocket *socket);//关闭连接时发送信号，从map中删除

public slots:
    void slotReadyRead();
    bool slotSendMsg(const QString& msg);
    void slotSendImage(const QString &msg, const QString& path);

public:
    explicit MsgSocket(QTcpSocket *socket, QObject *parent = nullptr);
    ~MsgSocket();

    QString m_localUid;

private:
    quint16 m_tcpBlockSize;
    QTcpSocket *m_tcpSocket;

    void parseUserLogin(QString msg);
    void parseUserExit(QString msg);
};

typedef QMap<QString, MsgSocket*> SocketMap;//id, socket


#endif // MSGSOCKET_H


